import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
import _regeneratorRuntime from "@babel/runtime/regenerator";

/**
 * model - 租户初始化处理器配置
 * @date: 2019/6/18

 */
import { getResponse } from 'utils/utils';
import { queryMapIdpValue } from 'cpaas-front/lib/services/api';
import { queryConfig, queryFormatConfig } from "../services/tenantInitConfig";
export default {
  namespace: 'tenantInitConfig',
  // model名称
  state: {
    configList: [],
    // 租户初始化处理器配置列表数据
    formatConfig: {},
    // 格式化处理器配置数据
    enumMap: {} // 值集

  },
  effects: {
    queryIdpValue: /*#__PURE__*/_regeneratorRuntime.mark(function queryIdpValue(_, _ref) {
      var call, put, enumMap;
      return _regeneratorRuntime.wrap(function queryIdpValue$(_context) {
        while (1) {
          switch (_context.prev = _context.next) {
            case 0:
              call = _ref.call, put = _ref.put;
              _context.t0 = getResponse;
              _context.next = 4;
              return call(queryMapIdpValue, {
                processorTypes: 'CPFM.TENANT_PROCESSOR_TYPE',
                initTypes: 'CPFM.TENANT_INIT_TYPE'
              });

            case 4:
              _context.t1 = _context.sent;
              enumMap = (0, _context.t0)(_context.t1);
              _context.next = 8;
              return put({
                type: 'updateState',
                payload: {
                  enumMap: enumMap
                }
              });

            case 8:
            case "end":
              return _context.stop();
          }
        }
      }, queryIdpValue);
    }),
    // 查询租户初始化处理器配置列表
    fetchConfigList: /*#__PURE__*/_regeneratorRuntime.mark(function fetchConfigList(_ref2, _ref3) {
      var payload, call, put, result;
      return _regeneratorRuntime.wrap(function fetchConfigList$(_context2) {
        while (1) {
          switch (_context2.prev = _context2.next) {
            case 0:
              payload = _ref2.payload;
              call = _ref3.call, put = _ref3.put;
              _context2.next = 4;
              return call(queryConfig, payload);

            case 4:
              result = _context2.sent;
              result = getResponse(result);

              if (!result) {
                _context2.next = 9;
                break;
              }

              _context2.next = 9;
              return put({
                type: 'updateState',
                payload: {
                  configList: result
                }
              });

            case 9:
            case "end":
              return _context2.stop();
          }
        }
      }, fetchConfigList);
    }),
    // 格式化查询租户初始化处理器配置
    fetchFormatConfig: /*#__PURE__*/_regeneratorRuntime.mark(function fetchFormatConfig(_, _ref4) {
      var call, put, result;
      return _regeneratorRuntime.wrap(function fetchFormatConfig$(_context3) {
        while (1) {
          switch (_context3.prev = _context3.next) {
            case 0:
              call = _ref4.call, put = _ref4.put;
              _context3.next = 3;
              return call(queryFormatConfig);

            case 3:
              result = _context3.sent;
              result = getResponse(result);

              if (!result) {
                _context3.next = 8;
                break;
              }

              _context3.next = 8;
              return put({
                type: 'updateState',
                payload: {
                  formatConfig: result
                }
              });

            case 8:
            case "end":
              return _context3.stop();
          }
        }
      }, fetchFormatConfig);
    })
  },
  reducers: {
    // 合并state状态数据,生成新的state
    updateState: function updateState(state, _ref5) {
      var payload = _ref5.payload;
      return _objectSpread(_objectSpread({}, state), payload);
    }
  }
};